SetOptions[EvaluationNotebook[],CellContext->Notebook]

Vectors

A vector in Mathematica is a list of numbers,e.g.

{0,1,0.5}

A list in Mathematica is a sequence of objects enclosed in curly brackets. Vectors are lists of numbers or symbols which are not themselves lists. For example

{1, 2, 3} and {a,b,c} are vectors but {1,{2,3}} is not a vector.

Vectors of the same dimension can be added and multiplied by scalars:

{2,3,4}+{1,2,3}

λ{2,3,4}

Mathematica has a built-in function whcih returns the length of a vector, called norm

?Norm

For exmple :

Norm[{1,1,1}]

However, in symbolic expressions Norm assumes that all the variables are complex:

Norm[{a,b,c}]

It is possible to deal with this by using Simplify with Assuming as follows:

Assuming[Element[{a,b,c},Reals],Simplify[Norm[{a,b,c}]]]

but it is more efficient to define vector length by means of the dot product (scalar product) of vectors

{a,b,c}.{e,f,g}

We will call our new function norm (we use a small letter to distinguish it from the built-in Norm):

norm[v_]:=(Sqrt[v.v])

norm[{a,b}]

norm[{a,b,c}]

Mathematica can verify the traingle and Cauchy-Schwarz inequality but only for a small number of variables:

Reduce[ForAll[{u,v,p,q},Element[{u,v,p,q},Reals],Norm[{u,v }+{p,q}]≤ Norm[{u,v}]+Norm[{p,q}]]]

Reduce[ForAll[{u,v,p,q},Element[{u,v,p,q},Reals],Abs[{u,v}.{p,q}]≤Norm[{p,q}] Norm[{u,v}]]]

Derivatives in Mathematica

Derivative of an expression

expr=x^2 y Exp[1/z]

D[expr,x]

D[expr,z]

D[expr,v]

D[expr,{z,2}]//Simplify

(((∂^2)expr)/(∂x ∂y))

D[expr,{{x,y,z}}]

D[expr,{{x,y,z},2}]

m=D[expr,{{x,y,z},3}]

m[[1,1,3]]

Grad[f[x,y,z],{x,y,z}]

?Grad

?*Tensor*

TensorQ[m]

TensorDimensions[m]

TensorTranspose[m]

TensorSymmetry[m]

Derivative of a function

f[x_,y_]:=x^2+y^2

Derivative[1, 0][f][x, y]

Derivative[0, 1][f][x, y]

Derivative[0, 1][f]

Derivative[1,1][Function[{x,y},x (y^2)]]

Derivative[1,1][#1 ((#2)^3)&][u,v]

Composition[f,g]'[x]

D[f[g[x]],x]

f[x_,y_]:= {x^2-y^2+2x,x^3-3x^2+1}

D[f[x,y],{{x,y}}]

?Derivative

g[t_]:={Sin[t],Cos[t]}

g'[t]

Parametric plots of curves in 3D and 2D

A parametric curve in (ℝ^n) is defined the image of a smooth function r: I -> (ℝ^n), where I is some interval (not necessarily finite). The same curve may be defined by more than one parametrisations.

(Subscript[r, 1])(t_):={cos(t),sin(t),t}

(Subscript[r, 2])(t_):={((1-(t^2))/((t^2)+1)),((2 t)/((t^2)+1)),2 (tan^(-1))(t)}

To plot a curve in (ℝ^3) we use the built-in Mathematica function ParametricPlot3D. (In (ℝ^2) ParametricPlot ).

(Subscript[p, 1])=ParametricPlot3D[(Subscript[r, 1])[t],{t,0,Pi},PlotStyle->Directive[Opacity[0.5],Blue]];
(Subscript[p, 2])=ParametricPlot3D[(Subscript[r, 2])[t],{t,0,Pi},PlotStyle->Directive[Opacity[0.5],Green]];

We can use the function Grid to show the two curves next to each other, but their relationship is not made clear:

Grid[{{(Subscript[p, 1]),(Subscript[p, 2])}}]

We can use Show to combine them into one picture:

Show[(Subscript[p, 1]),(Subscript[p, 2])]

Clearly the two parametrisations describe the same curve. We  can see the dynamics of the motion. The dynamics is created using the  Mathematica function Manipulate.

Manipulate[Show[Graphics3D[{PointSize[0.02],Red,If[t≤Pi,Point[(Subscript[r, 1])[t]],Point[(Subscript[r, 1])[Pi]]],Purple,Point[(Subscript[r, 2])[t]]}],(Subscript[p, 1])],{t,0,20,Appearance->"Labeled"},SaveDefinitions->True]

We can also use ParametricPlot  for more complicted functions, e.g. piecewise defined functions

Piecewise

f[t_]:=Piecewise[{{{2Cos[t],2Sin[t]},0≤t≤2Pi},{{Cos[t],Sin[t]},2Pi≤t≤4Pi}}]

ParametricPlot[f[t],{t,0,4Pi}]

curveLength[g_,t_,{a_,b_}]:=NIntegrate[Norm[D[g,t]],{t,a,b}]

curveLength[(Subscript[r, 1])[t],t,{0,Pi}]

curveLength[(Subscript[r, 2])[t],t,{0,∞}]

Manipulate[Show[Graphics3D[{PointSize[0.02],Red,If[t≤Pi,{Point[(Subscript[r, 1])[t]],Arrow[{(Subscript[r, 1])[t],(Subscript[r, 1])[t]+(Subscript[r, 1])'[t]}]},Point[(Subscript[r, 1])[Pi]]],Purple,Point[(Subscript[r, 2])[t]],,Arrow[{(Subscript[r, 2])[t],(Subscript[r, 2])[t]+(Subscript[r, 2])'[t]}]}],(Subscript[p, 1]),PlotRange->{{-1,1},{-1,1},{0,3}}],{t,0,20,Appearance->"Labeled"},SaveDefinitions->True]

Manipulate[Grid[{{Show[Graphics3D[{PointSize[0.02],Red,If[t≤Pi,{Point[(Subscript[r, 1])[t]],Arrow[{(Subscript[r, 1])[t],(Subscript[r, 1])[t]+(Subscript[r, 1])'[t]}]},Point[(Subscript[r, 1])[Pi]]],Purple,Point[(Subscript[r, 2])[t]],,Arrow[{(Subscript[r, 2])[t],(Subscript[r, 2])[t]+(Subscript[r, 2])'[t]}]}],(Subscript[p, 1])],Style[curveLength[(Subscript[r, 1])[s],s,{0,Min[Pi,t]}],Red],Style[curveLength[(Subscript[r, 2])[s],s,{0,t}],Blue]}}],{t,0,20,Appearance->"Labeled"},SaveDefinitions->True]

ContourPlot[Cos[x]+Cos[y]==1/2,{x,0,4Pi},{y,0,4Pi}]

cassini[a_,b_][x_,y_]:=(x^2 + y^2 + a^2)^2 - b^4 - 4*a^2*x^2

ContourPlot[cassini[2.01,2][x,y]==0,{x,-4,4},{y,-2,2}]

Manipulate[ContourPlot[cassini[a,b][x,y]==0,{x,-4,4},{y,-2,2}],{{a,2.01,"a"},-4,4,Appearance->"Labeled"},{{b,2.,"b"},-4,4,Appearance->"Labeled"},SaveDefinitions->True]

Singular and regular points of curves

Clear[f]

For a curve

f(x,y)==0

(({{Derivative[1,0][f](x,y), Derivative[0,1][f](x,y)}}))≠{0,0}

For a curve

{x,y}={ϕ(t),ψ(t)}

(lim_(t->0)) (((∂{ϕ(t),ψ(t)})/(∂t))/(Norm[((∂{ϕ(t),ψ(t)})/(∂t))]))

exists.